package com.tianji.aigc.controller;

import com.tianji.aigc.dto.ChatDto;
import com.tianji.aigc.service.IChatService;
import com.tianji.aigc.vo.ChatEventVO;
import com.tianji.aigc.vo.TemplateVO;
import com.tianji.common.annotations.NoWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import reactor.core.publisher.Flux;

/**
 * 聊天对话Controller
 *
 * @Author mr.wu
 * @Date 2025-9-2 15:53
 */
@RestController
@RequestMapping("/chat")
public class ChatController {

    @Autowired
    private IChatService chatService;

    /**
     * 流式对话
     * @param dto
     * @return
     */
    @NoWrapper
    @PostMapping(produces = MediaType.TEXT_EVENT_STREAM_VALUE)//指定响应数据类型为流式输出类型
    public Flux<ChatEventVO> chat(@RequestBody ChatDto dto) {
        return chatService.chat(dto);
    }

    /**
     * 停止生成
     * @param sessionId
     */
    @PostMapping("/stop")
    public void stop(String sessionId){
        chatService.stop(sessionId);
    }

    /**
     * 文本聊天
     * @param text
     */
    @PostMapping("/text")
    public String text(@RequestBody String text) {

        return chatService.chatText(text);
    }

    private static final TemplateVO TEMPLATE_VO = new TemplateVO();

    @GetMapping("/templates")
    public TemplateVO getTemplates() {
        return TEMPLATE_VO;
    }
}
